//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
namespace DotNetNuke.UI.UserControls
{
	public abstract class User : Framework.UserControlBase
	{
		protected UI.UserControls.LabelControl plFirstName;
		protected System.Web.UI.WebControls.TextBox txtFirstName;
		protected System.Web.UI.WebControls.RequiredFieldValidator valFirstName;
		protected UI.UserControls.LabelControl plLastName;
		protected System.Web.UI.WebControls.TextBox txtLastName;
		protected System.Web.UI.WebControls.RequiredFieldValidator valLastName;
		protected UI.UserControls.LabelControl plUserName;
		protected System.Web.UI.WebControls.TextBox txtUsername;
		protected System.Web.UI.WebControls.RequiredFieldValidator valUsername;
		protected System.Web.UI.WebControls.Label lblUsernameAsterisk;
		protected System.Web.UI.WebControls.Label lblUsername;
		protected System.Web.UI.HtmlControls.HtmlTableRow PasswordRow;
		protected UI.UserControls.LabelControl plPassword;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.RequiredFieldValidator valPassword;
		protected System.Web.UI.HtmlControls.HtmlTableRow ConfirmPasswordRow;
		protected UI.UserControls.LabelControl plConfirm;
		protected System.Web.UI.WebControls.TextBox txtConfirm;
		protected System.Web.UI.WebControls.RequiredFieldValidator valConfirm1;
		protected System.Web.UI.WebControls.CompareValidator valConfirm2;
		protected UI.UserControls.LabelControl plEmail;
		protected System.Web.UI.WebControls.TextBox txtEmail;
		protected System.Web.UI.WebControls.RequiredFieldValidator valEmail1;
		protected System.Web.UI.WebControls.RegularExpressionValidator valEmail2;
		protected UI.UserControls.LabelControl plWebsite;
		protected System.Web.UI.WebControls.TextBox txtWebsite;
		protected UI.UserControls.LabelControl plIM;
		protected System.Web.UI.WebControls.TextBox txtIM;
		private int _ModuleId;
		private bool _ShowPassword;
		private string _LabelColumnWidth = "";
		private string _ControlColumnWidth = "";
		private int _StartTabIndex = 1;
		private string _FirstName;
		private string _LastName;
		private string _UserName;
		private string _Password;
		private string _Confirm;
		private string _Email;
		private string _Website;
		private string _IM;
		private string MyFileName = "User.ascx";
		public int ModuleId {
			get { return Convert.ToInt32(ViewState["ModuleId"]); }
			set { _ModuleId= value; }
		}
		public string LabelColumnWidth {
			get { return Convert.ToString(ViewState["LabelColumnWidth"]); }
			set { _LabelColumnWidth= value; }
		}
		public string ControlColumnWidth {
			get { return Convert.ToString(ViewState["ControlColumnWidth"]); }
			set { _ControlColumnWidth= value; }
		}
		public string FirstName {
			get { return txtFirstName.Text; }
			set { _FirstName= value; }
		}
		public string LastName {
			get { return txtLastName.Text; }
			set { _LastName= value; }
		}
		public string UserName {
			get { return txtUsername.Text; }
			set { _UserName= value; }
		}
		public string Password {
			get { return txtPassword.Text; }
			set { _Password= value; }
		}
		public string Confirm {
			get { return txtConfirm.Text; }
			set { _Confirm= value; }
		}
		public string Email {
			get { return txtEmail.Text; }
			set { _Email= value; }
		}
		public string Website {
			get { return txtWebsite.Text; }
			set { _Website= value; }
		}
		public string IM {
			get { return txtIM.Text; }
			set { _IM= value; }
		}
		public int StartTabIndex {
			set { _StartTabIndex= value; }
		}
		public bool ShowPassword {
			set { _ShowPassword= value; }
		}
		public string LocalResourceFile {
			get { return Services.Localization.Localization.GetResourceFile(this, MyFileName); }
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			try {
				if (Page.IsPostBack == false) {
					txtFirstName.TabIndex = Convert.ToInt16(_StartTabIndex);
					txtLastName.TabIndex = Convert.ToInt16(_StartTabIndex + 1);
					txtUsername.TabIndex = Convert.ToInt16(_StartTabIndex + 2);
					txtPassword.TabIndex = Convert.ToInt16(_StartTabIndex + 3);
					txtConfirm.TabIndex = Convert.ToInt16(_StartTabIndex + 4);
					txtEmail.TabIndex = Convert.ToInt16(_StartTabIndex + 5);
					txtWebsite.TabIndex = Convert.ToInt16(_StartTabIndex + 6);
					txtIM.TabIndex = Convert.ToInt16(_StartTabIndex + 7);
					txtFirstName.Text = _FirstName;
					txtLastName.Text = _LastName;
					txtUsername.Text = _UserName;
					lblUsername.Text = _UserName;
					txtPassword.Text = _Password;
					txtConfirm.Text = _Confirm;
					txtEmail.Text = _Email;
					txtWebsite.Text = _Website;
					txtIM.Text = _IM;
					if (!String.IsNullOrEmpty(_ControlColumnWidth)) {
						txtFirstName.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtLastName.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtUsername.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtPassword.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtConfirm.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtEmail.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtWebsite.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtIM.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
					}
					if (!_ShowPassword) {
						valPassword.Enabled = false;
						valConfirm1.Enabled = false;
						valConfirm2.Enabled = false;
						PasswordRow.Visible = false;
						ConfirmPasswordRow.Visible = false;
						txtUsername.Visible = false;
						valUsername.Enabled = false;
						lblUsername.Visible = true;
						lblUsernameAsterisk.Visible = false;
					} else {
						txtUsername.Visible = true;
						valUsername.Enabled = true;
						lblUsername.Visible = false;
						lblUsernameAsterisk.Visible = true;
						valPassword.Enabled = true;
						valConfirm1.Enabled = true;
						valConfirm2.Enabled = true;
						PasswordRow.Visible = true;
						ConfirmPasswordRow.Visible = true;
					}
					ViewState["ModuleId"] = Convert.ToString(_ModuleId);
					ViewState["LabelColumnWidth"] = _LabelColumnWidth;
					ViewState["ControlColumnWidth"] = _ControlColumnWidth;
				}
				txtPassword.Attributes.Add("value", txtPassword.Text);
				txtConfirm.Attributes.Add("value", txtConfirm.Text);
			} catch (Exception exc) {
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
	}
}
